import tuio
import PyRec
import pygame

tela = pygame.display.set_mode((400, 400))
tela.fill((255, 255, 255))

class Listener(tuio.observer.AbstractListener):
    def __init__(self, name, subject):
        tuio.observer.AbstractListener.__init__(self, name, subject)
        self.points = []
        self.id = -1
        self.recog = PyRec.Recognizer()
        
    #Implements a Listener
    def notify(self, event):
        if (self.id != event.object.sessionid):
            if self.points != []:
                tela.fill((255, 255, 255))
                try:
                    PyRec.Recognizer().recognize(self.points)
                except PyRec.FewPointsError:
                    print 'Few Points Made'
            self.points = []
            self.id = event.object.sessionid
        tela.blit(pygame.Surface((5,5)),((int(400*event.object.xpos)), (int(400*event.object.ypos))))
        pygame.display.update()
        self.points.append(PyRec.Point(event.object.xpos,event.object.ypos))

        
  
listener = Listener("Event Listener", tuio.getEventManager())
tuio.mainLoop()